import archiver from 'archiver'
import fs from 'fs'
import path from 'path'

const output = fs.createWriteStream('dice-plugin.upx')
const archive = archiver('zip', {
  zlib: { level: 9 }
})

output.on('close', () => {
  console.log('Plugin has been packed successfully!')
})

archive.on('error', (err) => {
  throw err
})

archive.pipe(output)

// 添加构建后的文件
archive.directory('dist/', false)

// 添加插件配置文件
archive.file('public/plugin.json', { name: 'plugin.json' })
archive.file('public/preload.js', { name: 'preload.js' })
archive.file('public/logo.png', { name: 'logo.png' })

archive.finalize() 